package _interview100;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;

/**
 * 763. 划分字母区间
 */
public class No763 {
    public List<Integer> partitionLabels(String s) {
        List<Integer> ans = new ArrayList<>();
        HashSet<Character> set = new HashSet<>();
        label:
        for (int i = 0; i < s.length(); i++) {
            set.add(s.charAt(i));
            for (Character c : set) {
                if (s.substring(i + 1).contains(c + "")) {
                    continue label;
                }
            }
            set.clear();
            ans.add(i + 1);
        }
        for (int i = ans.size() - 1; i >= 1; i--) {
            ans.set(i, ans.get(i) - ans.get(i - 1));
        }
        return ans;
    }
}
